/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class TestDemo {
    public static void main(String[] args) {
        int[] array = {0,1,2,3,4,5,6,7,8,9};
        int ret = binarySearch(array,1);
        System.out.println(ret);
    }

    public static int binarySearch(int[] array,int key){
        int left = 0;
        int right = array.length-1;
        int mid = array.length/2;
        while(left <= right){
            if(array[mid] < key){
                left = mid+1;
            }else if (array[mid] > key){
                right = mid-1;
            }else{
                return mid;
            }
            mid = (right+left)/2;
        }return -1;
    }

}
